#!/bin/bash
ORIG=$1
SIGNED=$2
OUTPUT=$3
 
TMP_SIGNED=$(mktemp)
 
grep -v "^$(grep 'SOA' $ORIG | head -n1 | awk '{print $1}')\\s*IN\\s*SOA" $SIGNED > $TMP_SIGNED
 
cat $ORIG $TMP_SIGNED > $OUTPUT
rm $TMP_SIGNED

if named-checkzone . $OUTPUT > /dev/null; then
    echo "Merge successful: $OUTPUT is valid."
else
    echo "Error: Merged zone is invalid!" >&2
    exit 1
fi
